package cn.stronglink.asset.module.inventory.controller;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.plugins.Page;
import cn.stronglink.asset.model.InventorySheet;
import cn.stronglink.asset.model.InventorySheetDetail;
import cn.stronglink.asset.module.inventory.service.InventoryService;
import cn.stronglink.asset.module.inventory.vo.InventoryVo;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value = "inventory")
public class InventoryController extends AbstractController {

	@Autowired
	private InventoryService inventoryService;

	/**
	 * 查询所有盘点并分页
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "queryList")
	public ResponseEntity<ModelMap> queryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<InventoryVo> page = (Page<InventoryVo>) super.getPage(params);
		Page<InventoryVo> data = inventoryService.queryList(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 根据盘点单Id查询明细
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long id) {	
		InventoryVo data =inventoryService.qryById(id);
		return setSuccessModelMap(modelMap, data);
	}
	/**
	 * 查询盘点对象  包含盘点详情
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "onViewItem")
	public ResponseEntity<ModelMap> onViewItem(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long sheetId) {	
		InventorySheet data =inventoryService.qryDetailById(sheetId);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 下达盘点命令(手动盘点)
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "goInventory")
	public ResponseEntity<ModelMap> goInventory(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long id) {	
		inventoryService.goInventory(id);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 查询盘点对象  包含盘点的资产
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "quryAssetByInventory")
	public ResponseEntity<ModelMap> quryAssetByInventory(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		Page<InventorySheetDetail> page = (Page<InventorySheetDetail>) super.getPage(params);
		Page<InventorySheetDetail> data = inventoryService.quryAssetByInventory(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 创建盘点单
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param inventory
	 * @return
	 */
	@OperateLog(module = "盘带计划管理",desc="创建盘点计划", type = OpType.ADD)
	@RequestMapping(value = "create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody InventoryVo inventory) {
		inventoryService.create(inventory);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 编辑盘点单
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param inventory
	 * @return
	 */
	@OperateLog(module = "盘带计划管理",desc="修改盘点计划", type = OpType.UPDATE)
	@RequestMapping(value = "edit")
	public ResponseEntity<ModelMap> edit(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody InventoryVo inventory) {
		inventoryService.edit(inventory);
		return setSuccessModelMap(modelMap, null);
	}
	/**
	 * 删除盘点单
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@OperateLog(module = "盘带计划管理",desc="删除盘点计划", type = OpType.DEL)
	@RequestMapping(value = "remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		inventoryService.remove(id);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 查看盘点计划下的盘点单
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "qrySheetById")
	public ResponseEntity<ModelMap> qrySheetById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<InventorySheet> page = (Page<InventorySheet>) super.getPage(params);
		Page<InventorySheet> data = inventoryService.qrySheetById(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	

}
